﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Radiation___IM.Data
{
    public class File
    {
        private string m_path;
        private Dictionary<string, string> m_fields;

        public string this[string line]
        {
            get
            {
                if (m_fields.ContainsKey(line))
                    return m_fields[line];
                return null;
            }
        }

        public ICollection<string> Values
        {
            get
            {
                return m_fields.Keys;
            }
        }

        public string Path
        {
            get
            {
                return this.m_path;
            }
        }

        public File(string path)
        {
            m_path = path;
            m_fields = new Dictionary<string, string>();
        }

        public rvalue addLine(string name, string value)
        {
            if (m_fields.ContainsKey(name))
                return rvalue.NAME_ALREDAY_EXISTS;
            else
            {
                if (value == null)
                    return rvalue.VALUE_IS_NULL;
                else
                {
                    m_fields.Add(name, value);
                    return rvalue.LINE_ADDED;
                }
            }
        }

        public rvalue removeLine(string name)
        {
            if (!m_fields.ContainsKey(name))
                return rvalue.NAME_NOR_FOUND;
            else
            {
                m_fields.Remove(name);
                return rvalue.LINE_REMOVED;
            }
        }
    }
}
